/*
 * @Description: 
 * @Author: zhuying
 * @Date: 2025-01-07 16:30:41
 * @LastEditors: zhuying
 * @LastEditTime: 2025-03-09 11:39:48
 */
public class HelloWorld {
    // Java的入口函数，有且仅有一个
    public static void main(String[] args) {
        // 输出
        System.out.println("Hello World");

        // 牛顿迭代法求平方根示例
        double number = 25.0;
        double sqrt = newtonSqrt(number);
        System.out.println("The square root of " + number + " is approximately " + sqrt);
    }

    // 牛顿迭代法求平方根
    public static double newtonSqrt(double n) {
        double x = n;
        double epsilon = 1e-7; // 精度
        while (Math.abs(x - n / x) > epsilon) {
            x = (x + n / x) / 2.0;
        }
        return x;
    }
}

